package com.paradogs.gs.modules.world.base;

import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import com.paradogs.common.utils.StreamUtils;
import com.paradogs.gs.modules.WorldObject;
import com.paradogs.gs.modules.WorldSyncData;
import com.paradogs.gs.modules.world.entity.WorldNode;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author: yumi
 * @date: 2025/4/17  23:39
 * @Description: TODO
 */
@Data
@ProtobufClass
@NoArgsConstructor
public class WorldNodeProto {
    // ID
    private Long id;
    // 所属场景 ID
    private Integer sceneId;
    // X 坐标
    private Integer x;
    // Y 坐标
    private Integer y;
    // 节点名称
    private String name;
    // 描述
    private String description;
    // 是否可以 pk
    private Boolean pk;
    // 存在的单位
    private Map<String, WorldSyncData> objectMap;
    // 周围节点
    private String north;    // 北
    private String east;     // 东
    private String south;    // 南
    private String west;     // 西

    public WorldNodeProto(WorldNode node) {
        this.id = node.getId();
        this.sceneId = node.getSceneId();
        this.x = node.getX();
        this.y = node.getY();
        this.name = node.getName();
        this.description = node.getDescription();
        this.pk = node.getPk();
        this.objectMap = new LinkedHashMap<>();
        node.getObjectMap().forEach((key, val) -> {
            objectMap.put(key.toString(), val.toSyncData());
        });
        this.north = node.getNorth() != null ? node.getNorth().getName() : null;
        this.east = node.getEast() != null ? node.getEast().getName() : null;
        this.south = node.getSouth() != null ? node.getSouth().getName() : null;
        this.west = node.getWest() != null ? node.getWest().getName() : null;
    }
}
